package com.isoftstone.project.device.station.controller;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.isoftstone.project.device.station.domain.UStation;
import com.isoftstone.project.device.station.service.IUStationService;
import com.isoftstone.framework.controller.BaseController;
import com.isoftstone.framework.domain.Page;
import com.isoftstone.framework.domain.Tidings;
import com.isoftstone.common.utils.ExcelUtil;
import com.isoftstone.framework.domain.PageData;

/**
 * 井下分站Controller
 *
 * @author guoX
 * @date 2021-02-02
 */
@Controller
@RequestMapping("/device/station")
public class UStationController extends BaseController {
    private String prefix = "device/station";

    @Autowired
    private IUStationService uStationService;

    @RequiresPermissions("device:station:view")
    @GetMapping()
    public String station() {
        return prefix + "/station_list";
    }

    /**
     * 查询井下分站列表
     */
    @RequiresPermissions("device:station:list")
    @PostMapping("/uStationlistPage")
    @ResponseBody
    public Object getuStationlistPage(Page page) {
        PageData pd = this.getPageData();
        page.setPd(pd);
        List<UStation> list = uStationService.getUStationlistPage(page);
        return Tidings.success(page.getTotalResult(), list);
    }


    /**
     * 导出井下分站列表
     */
    @RequiresPermissions("device:station:export")
    @PostMapping("/exportUStation")
    @ResponseBody
    public Object exportUStation(Page page) {
        PageData pd = this.getPageData();
        page.setPd(pd);
        page.setEntityOrField(false);
        List<UStation> list = uStationService.getUStationlistPage(page);
        ExcelUtil<UStation> util = new ExcelUtil<UStation>(UStation. class);
        return util.exportExcel(list, "station");
    }

    /**
     * 新增井下分站
     */
    @GetMapping("/addUStation")
    public String addUStation() {
        return prefix + "/station_add";
    }


    /**
     * 新增保存井下分站
     */
    @RequiresPermissions("device:station:add")
    @PostMapping("/addUStation")
    @ResponseBody
    public Object insertUStation(UStation uStation) {
        uStationService.insertUStation(uStation);
        return Tidings.success();

    }

    /**
     * 修改井下分站
     */
    @GetMapping("/toEditUStation")
    public String toEditUStation(Long id, ModelMap mmap) {
        UStation uStation =uStationService.getUStationById(id);
        mmap.put("uStation", uStation);
        return prefix + "/station_edit";
    }

    /**
     * 修改保存井下分站
     */
    @RequiresPermissions("device:station:edit")
    @PostMapping("/updateUStation")
    @ResponseBody
    public Object updateUStation(UStation uStation) {
        uStationService.updateUStation(uStation);
        return Tidings.success();
    }

    /**
     * 删除井下分站
     */
    @RequiresPermissions("device:station:remove")
    @PostMapping("/deleteUStation")
    @ResponseBody
    public Object deleteUStation(String id) {
        uStationService.deleteUStationByIds(id);
        return Tidings.success();
    }

}
